<?php

declare(strict_types=1);

namespace app\api\model;

use app\common\model\Product;
use Exception;
use think\Model;

/**
 * @mixin \think\Model
 */
class UserCareProduct extends Model
{


    public function product()  {
        return $this->belongsTo(Product::class,'product_id');
    }

    //收藏or取消
    public static function careProductModel($product_id, $user_id)
    {
        $row = self::where(['product_id' => $product_id, 'user_id' => $user_id])->find();
        if (!$row) {
            return self::create(['product_id' => $product_id, 'user_id' => $user_id]);
        } else {
            return $row->delete(); //取消
        }
    }
}
